package com.yjhh.chdataservice.controller;

import com.google.gson.Gson;
import com.yjhh.chdataservice.beans.*;
import com.yjhh.chdataservice.except.YJHHException;
import com.yjhh.chdataservice.service.FZJCObjService;
import com.yjhh.chdataservice.service.FZJCPlacementPointService;
import com.yjhh.chdataservice.util.CommonResultData;
import com.yjhh.chdataservice.util.PageResultData;
import com.yjhh.chdataservice.util.XaUtil;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 辅助决策总览模块Controller
 */
@Api(tags = "总览模块相关接口")
@RestController
@RequestMapping(value = "/service/fzjc/overview")
@Log4j2
public class FZJCOverviewController {
    
    @Autowired
    private FZJCPlacementPointService fzjcPlacementPointService;
    
    @Autowired
    private FZJCObjService fzjcService;
    
    @ApiOperation(value = "根据行政区划返回所属范围内的所有安置点的就业岗位安置情况", notes = "根据行政区划返回所属范围内的所有安置点的就业岗位安置情况")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getJYGWInfoByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<TPJYPostTypeInfoVo>> getJYGWInfoByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<TPJYPostTypeInfoVo>> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getJYGWInfoByAreaCode(areaCode);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getJYGWInfoByAreaCode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }
    
    @ApiOperation(value = "根据行政区划返回按人口规模统计安置点数量", notes = "根据行政区划返回按人口规模统计安置点数量")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPointScaleStatisticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<CommonNameValueVo>> getPointScaleStatisticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<CommonNameValueVo>> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getPointScaleStatisticsByAreaCode(areaCode);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPointScaleStatisticsByAreaCode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }
    
    @ApiOperation(value = "根据行政区划返回按选址情况统计安置点数量", notes = "根据行政区划返回按选址情况统计安置点数量")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPointSelectedAddrStatisticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<CommonNameValueVo>> getPointSelectedAddrStatisticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<CommonNameValueVo>> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getPointSelectedAddrStatisticsByAreaCode(areaCode);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPointSelectedAddrStatisticsByAreaCode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }
    
    @ApiOperation(value = "根据行政区划返回脱贫情况统计", notes = "根据行政区划返回脱贫情况统计")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getThrowOffPovertyInfoByAreacode", method = RequestMethod.GET)
    public CommonResultData<List<CommonNameValueVo>> getThrowOffPovertyInfoByAreacode(@RequestParam String areaCode) {
        CommonResultData<List<CommonNameValueVo>> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getThrowOffPovertyInfoByAreacode(areaCode);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getThrowOffPovertyInfoByAreacode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }
    
    @ApiOperation(value = "根据行政区划返回开工竣工安置点比率统计", notes = "根据行政区划返回开工竣工安置点比率统计")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getStartAndEndPointStatisticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<Map<String,Long>> getStartAndEndPointStatisticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<Map<String,Long>> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getStartAndEndPointStatisticsByAreaCode(areaCode);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getStartAndEndPointStatisticsByAreaCode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }
    
    @ApiOperation(value = "根据行政区划返回入住和交钥匙的户数比率统计", notes = "根据行政区划返回入住和交钥匙的户数比率统计")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getTurnKeyAndMoveInObjByAreaCode", method = RequestMethod.GET)
    public CommonResultData<Map<String,Long>> getTurnKeyAndMoveInObjByAreaCode(@RequestParam String areaCode) {
        CommonResultData<Map<String,Long>> statisticsResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticsResult = fzjcPlacementPointService.getTurnKeyAndMoveInObjByAreaCode(areaCode);
            statisticsResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getTurnKeyAndMoveInObjByAreaCode", e);
            statisticsResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticsResult;
    }
    
    @ApiOperation(value = "根据贫困户的ID返回贫困户的所有属性信息", notes = "根据贫困户的ID返回贫困户的所有属性信息")
    @ApiImplicitParam(name = "id", value = "贫困户ID", required = true, paramType = "query", dataType = "String", defaultValue =
            "71f241da-c8b3-44a1-a1dd-8d7ed5a0bea3")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPoorObjInfoById", method = RequestMethod.GET)
    public CommonResultData<ObjMoveInfoVo> getPoorObjInfoById(@RequestParam String id) {
        CommonResultData<ObjMoveInfoVo> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            moveTopByAreaCode = fzjcService.getPoorObjDetailInfoById(id);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPoorObjInfoById", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }

    @ApiOperation(value = "根据安置点ID获取安置点详细信息", notes = "根据安置点ID获取安置点详细信息")
    @ApiImplicitParam(name = "pointId", value = "安置点ID", required = true, paramType = "query", dataType = "String", defaultValue = "1d3705db-46c1-4449-a515-fce6a3fb83cc")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPlacementPointDetailByPointId", method = RequestMethod.GET)
    public CommonResultData<PlacementPointDetailVo> getPlacementPointDetailByPointId(@RequestParam String pointId) {
        CommonResultData<PlacementPointDetailVo> pointListResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getPlacementPointDetailByPointId(pointId);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementPointDetailByPointId", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }
    @ApiOperation(value = "根据安置点ID获取安置对象规模", notes = "根据安置点ID获取安置对象规模")
    @ApiImplicitParam(name = "pointId", value = "安置点ID", required = true, paramType = "query", dataType = "String", defaultValue = "1d3705db-46c1-4449-a515-fce6a3fb83cc")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPlacementScaleByPointId", method = RequestMethod.GET)
    public CommonResultData<MovePeopleNumVo> getPlacementScaleByPointId(@RequestParam String pointId) {
        CommonResultData<MovePeopleNumVo> pointListResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getPlacementScaleByPointId(pointId);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementScaleByPointId", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }

    @ApiOperation(value = "根据搜索条件查询搬迁户", notes = "根据搜索条件查询搬迁户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pointId", value = "安置点ID", required = true, paramType = "query", dataType = "String", defaultValue = "1d3705db-46c1-4449-a515-fce6a3fb83cc"),
            @ApiImplicitParam(name = "relFamilyName", value = "户主姓名", required = true, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "idCard", value = "身份证号", required = true, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "removalType", value = "搬迁类型", required = true, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "sftp", value = "是否脱贫", required = true, paramType = "query", dataType = "String", defaultValue = ""),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getRelocatedFamily", method = RequestMethod.GET)
    public PageResultData<List<ObjBaseInfoVo>> getRelocatedFamily(@RequestParam String pointId,
                                                            @RequestParam(value = "relFamilyName", required = false, defaultValue = "") String relFamilyName,
                                                            @RequestParam(value = "idCard", required = false, defaultValue = "")  String idCard,
                                                            @RequestParam(value = "removalType", required = false, defaultValue = "")  String removalType,
                                                            @RequestParam(value = "sftp", required = false, defaultValue = "")  String sftp,
                                                            @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                                                            @RequestParam(value = "size", required = false, defaultValue = "8") int size) {
        PageResultData<List<ObjBaseInfoVo>> pointListResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getRelocatedFamily(pointId,relFamilyName,idCard,removalType,sftp,pageNum,size);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementScaleByPointId", e);
            pointListResult = new PageResultData();
        }
        return pointListResult;
    }


    @ApiOperation(value = "获取搬迁对象", notes = "获取搬迁对象")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getMovingObject", method = RequestMethod.GET)
    public CommonResultData<PlacementScaleVo> getMovingObject(String areaCode) {
        CommonResultData<PlacementScaleVo> pointListResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getMovingObject(areaCode);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementScaleByPointId", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }

    @ApiOperation(value = "搜索搬迁对象", notes = "搜索搬迁对象")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @ApiImplicitParam(name = "searchMoveObj", value = "查询条件json", required = true, paramType = "query", dataType = "String", defaultValue = "")
    @RequestMapping(value = "/searchMovingObject", method = RequestMethod.GET)
    public CommonResultData<MoveObjChartVo> searchMovingObject(@RequestParam String searchMoveObj) {
        CommonResultData<MoveObjChartVo> pointListResult = null;
        if(XaUtil.isEmpty(searchMoveObj)){
            return pointListResult;
        }
        Gson gson = new Gson();
        SearchMoveObjVo searchMoveObjVo = gson.fromJson(searchMoveObj, SearchMoveObjVo.class);//对于javabean直接给出class实例

        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.searchMovingObject(searchMoveObjVo);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementScaleByPointId", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }

    @ApiOperation(value = "搜索搬迁户信息", notes = "搜索搬迁户信息")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @ApiImplicitParam(name = "searchMoveObj", value = "查询条件json", required = true, paramType = "query", dataType = "String", defaultValue = "")
    @RequestMapping(value = "/searchObjBaseInfo", method = RequestMethod.GET)
    public PageResultData<List<ObjBaseInfoVo>> searchObjBaseInfo(@RequestParam String searchMoveObj) {
        PageResultData<List<ObjBaseInfoVo>> pointListResult = null;
        if(XaUtil.isEmpty(searchMoveObj)){
            return pointListResult;
        }
        Gson gson = new Gson();
        SearchMoveObjVo searchMoveObjVo = gson.fromJson(searchMoveObj, SearchMoveObjVo.class);//对于javabean直接给出class实例

        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.searchObjBaseInfo(searchMoveObjVo);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementScaleByPointId", e);
            pointListResult = new PageResultData();
        }
        return pointListResult;
    }

    @ApiOperation(value = "获取区域信息", notes = "获取区域信息")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @ApiImplicitParam(name = "areaCode", value = "区域id", required = true, paramType = "query", dataType = "String", defaultValue = "")
    @RequestMapping(value = "/getSysDeptInfo", method = RequestMethod.GET)
    public CommonResultData<SysDeptInfoVo> getSysDeptInfo(@RequestParam String areaCode) {
        CommonResultData<SysDeptInfoVo> pointListResult = null;

        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getSysDeptInfo(areaCode);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementScaleByPointId", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }

    @ApiOperation(value = "根据code获取字典值", notes = "根据code获取字典值")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictId", value = "字典id", required = false, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "dictpId", value = "字典父id", required = false, paramType = "query", dataType = "String", defaultValue = ""),
    })
    @RequestMapping(value = "/getDictInfo", method = RequestMethod.GET)
    public CommonResultData<Map<String,String>> getDictInfo(@RequestParam(value = "dictId", defaultValue = "",required = false) String dictId,
                                                          @RequestParam(value = "dictpId", defaultValue = "",required = false) String dictpId) {
        CommonResultData<Map<String,String>> pointListResult = null;

        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcService.getDictInfo(dictId,dictpId);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementScaleByPointId", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }

    @ApiOperation(value = "搜索安置点", notes = "搜索安置点")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @ApiImplicitParam(name = "searchPlacementPoint", value = "查询条件json", required = true, paramType = "query", dataType = "String", defaultValue = "")
    @RequestMapping(value = "/searchPlacementPoint", method = RequestMethod.GET)
    public CommonResultData<PlacementPointChartVo> searchPlacementPoint(@RequestParam String searchPlacementPoint) {
        CommonResultData<PlacementPointChartVo> pointListResult = null;
        if(XaUtil.isEmpty(searchPlacementPoint)){
            return pointListResult;
        }
        Gson gson = new Gson();
        SearchPlacementPointVo searchPlacementPointVo = gson.fromJson(searchPlacementPoint, SearchPlacementPointVo.class);//对于javabean直接给出class实例

        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.searchPlacementPoint(searchPlacementPointVo);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementScaleByPointId", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }

    @ApiOperation(value = "搜索安置点信息分页展示", notes = "搜索安置点信息分页展示")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @ApiImplicitParam(name = "searchPlacementPoint", value = "查询条件json", required = true, paramType = "query", dataType = "String", defaultValue = "")
    @RequestMapping(value = "/searchPlacementPointBaseInfo", method = RequestMethod.GET)
    public PageResultData<List<PlacementPointBaseInfoVo>> searchPlacementPointBaseInfo(@RequestParam String searchPlacementPoint) {
        PageResultData<List<PlacementPointBaseInfoVo>> pointListResult = null;
        if(XaUtil.isEmpty(searchPlacementPoint)){
            return  new PageResultData(HttpStatus.OK.value(), "no data");
        }
        Gson gson = new Gson();
        SearchPlacementPointVo searchPlacementPointVo = gson.fromJson(searchPlacementPoint, SearchPlacementPointVo.class);//对于javabean直接给出class实例

        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.searchPlacementPointBaseInfo(searchPlacementPointVo);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementScaleByPointId", e);
            pointListResult =  new PageResultData(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }


}
